package src

import (
	"database/sql"
	"os"

	_ "github.com/godror/godror"
	_ "github.com/lib/pq"
	"github.com/sirupsen/logrus"
)

var (
	err            error
	dbCrms, dbSign *sql.DB
	wxchatURL      string // 企业微信机器人 key
)

func init() {
	wxchatURL = os.Getenv("wxchatURL")
	if wxchatURL == "" {
		logrus.Fatal("no environment: wxchatURL!")
	}
	// crms数据库
	crms := os.Getenv("crms")
	if crms == "" {
		logrus.Fatal("no environment: crms!")
	}
	dbCrms, err = sql.Open("godror", crms)
	if err != nil {
		logrus.Fatal("open crms fail ", err.Error())
	}
	err = dbCrms.Ping()
	if err != nil {
		logrus.Fatal("ping crms error ", err.Error())
	}

	// pg 策略信号库
	sign := os.Getenv("sign")
	if sign == "" {
		logrus.Fatal("缺少环境变量: sign")
	}
	dbSign, err = sql.Open("postgres", sign)
	if err != nil {
		logrus.Fatal("open postgres fail ", err.Error())
	}
	err = dbSign.Ping()
	if err != nil {
		logrus.Fatal("ping postgres error ", err.Error())
	}
}
